package com.wolfword.crawler.client.scheduler;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.wolfword.crawler.client.deal.ConnectServer;

/**
 * 发送客户端状态定时器
 * @author ServerZhang
 * @date 2018年1月24日
 */
@Component
@EnableScheduling 
public class SendStatusScheduler {
	
	private ExecutorService threadPool = null;
	
	private SendStatusScheduler(){
		threadPool = Executors.newCachedThreadPool(new ThreadFactory() {
			@Override
			public Thread newThread(Runnable r) {
				Thread thread = new Thread(r);
				thread.setDaemon(true);
				return thread;
			}
		});
	}
	/**
	 * 每分钟向服务端发送自己状态
	 * @throws InterruptedException
	 * @author ServerZhang
	 * @date 2017年7月5日
	 */
	@Scheduled(cron = "0 0/1 * * * ?")  
	public void creatTask() throws InterruptedException{
		threadPool.execute(new Runnable(){
			@Override 
			public void run() { 
				ConnectServer.sendMyStatus();
			} 
		});            
	}
}
